<?php
class a_showService extends Service{
	
	public function __construct(){
		parent::__construct();
        
        $this->url_service=load_service('url',P_SVC);
        $this->url_service->set_module_id(11);
        
		$this->table=table('arc');
		$this->table_attr=table('attrtaglist');
		$this->table_word=table('wordtaglist');
		
		$this->table_cate=table('category');
		
		//$this->table_b=table('word_base');
		$this->table_b='word_base';
		$this->table_index_1=table('index_1');
	}
	public function mylevel($l){
		$d=array();
		//'static_rule_list_index'=>array('/html/{level_id}/index.html',ROOT.'html/{level_id}/index.html'),
		$query="select `id`,`name` from `{$this->table_cate}` where `id`='{$l}' limit 1";
		$result=$this->m->query($query);
		$d=$this->m->select($query);
        list($d['linkurl'],)=$this->url_service->var_list_index($d['id'])->list_index();
		return $d;
	}
	//文章的标签
	public function tags($arc_id){
		$query="select `tag` from `{$this->table_attr}` where `arc_id`='{$arc_id}'";
		$info=$this->m->mselect($query);
		if(empty($info)) return array();
		return multi2single_min($info,'tag');
	}
	public function get_tagid($tag){
		$query="select `id` from `{$this->table_index_1}` where `tag`='{$tag}' limit 1";
		return $this->m->get_field($query);
	}
	private function _map($l){
		$arr=include(P_INC.'_map.php');
		return $arr[$l];
	}
	//单词标签
	public function wordtags($arc_id,$level_id){
		$ls=$this->_map($level_id);
		$query="select `l`.`tag`,`l`.`index`,`l`.`level_id`,`b`.`id`,`b`.`word`,`b`.`spell`,`b`.`explain`,`b`.`sentence`,`b`.`src` from `{$this->table_word}` `l` left join `{$this->table_b}` `b` on `l`.`tag`=`b`.`word` where `l`.`arc_id`='{$arc_id}' and `l`.`level_id`>='{$ls[0]}' order by `l`.`index` asc";
		return $this->m->mselect($query);
	}
	//w
	public function wwwww($arc_id,$n=5){
		$query="select `tag` from `{$this->table_word}` where `arc_id`='{$arc_id}' and `index`>0 limit {$n}";
		$info=$this->m->mselect($query);
		if(empty($info)) return array();
		return multi2single_min($info,'tag');
	}
	//文章的上一篇 下一篇
	public function prev_next_arc($current_id){
		$return=array(
			0=>array(),
			1=>array()
		);
		//上一篇
		$query="select `id`,`title`,`htmlurl` from `{$this->table}` where `status`='1' and `id`<'{$current_id}' order by `id` desc limit 1";
		$r1=$this->m->select($query);
		//下一篇
		$query="select `id`,`title`,`htmlurl` from `{$this->table}` where `status`='1' and `id`>'{$current_id}' order by `id` asc limit 1";
		$r2=$this->m->select($query);
		
		if($r1['id']) $return[0]=$r1;
		if($r2['id']) $return[1]=$r2;
		return $return;
	} 

//
}